var fs = require("fs")

// var cc = require("../../views/front-stage/myperson.html")
const jwt = require("jsonwebtoken")


const express = require('express')
const { resourceUsage } = require('process')

var globalsearchRouter = express.Router()

var axios = require("axios");

globalsearchRouter.get('/globalsearch', function (req, res) {

    if (req.session.token == undefined) {
        axios({
            url: "video/order/findAllVip",
            method: "post",
        })
            .then(function (data) {
                let allonevip = data.data.object
                res.render("front-stage/globalsearch.html", { userinfo: '', allonevip: allonevip })
            })
            .catch(function (error) {
                console.log(error)
                res.status(500).json({
                    message: '获取黄金vip失败'
                })
            })
    } else {


    axios({
        url: "video/order/findAllVip",
        method: "post",
    })
        .then(function (data) {
            let allonevip = data.data.object
            res.render("front-stage/globalsearch.html", { userinfo: jwt.decode(req.session.token), allonevip: allonevip})
        })
        .catch(function (error) {
            console.log(error)
            res.status(500).json({
                message: '获取黄金vip失败'
            })
        })

    }



    })



globalsearchRouter.get('/findAllVideoByLikeKeyWords', function (req, res) {
    axios({
        url: "video/index/findAllVideoByLikeKeyWords",
        method: "get",
        params: {
            keyWords: req.query.keyWords,
        }
    })
        .then(function (data) {
            res.status(200).json({
                code: 200,
                data: data.data,
                message: '全局模糊查询作品成功'
            })
        })
        .catch(function (error) {
            console.log(error)
            res.status(500).json({
                message: '全局模糊查询作品失败'
            })
        })
})
//遍历出来几个电视剧的名字
globalsearchRouter.get('/index/MoreTV', function (req, res) {
    axios({
        url: "video/index/MoreTV",
        method: "get"
    })
        .then(function (data) {
            res.status(200).json({
                data: data.data.data,
            })
        })
        .catch(function (error) {
            res.status(500).json({
                message: '失败'
            })
        })
})

module.exports = globalsearchRouter;